home *** CD-ROM | disk | FTP | other *** search
- Path: atglab.bls.com!Alun.Champion
- From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
- Newsgroups: comp.lang.c
- Subject: Re: Question about system call
- Date: 18 Jan 1996 17:09:27 GMT
- Organization: Computer People Inc.
- Message-ID: <ALUN.CHAMPION.96Jan18120927@g7240065.bridge.bst.bls.com>
- References: <4dekv8$9ja@spider.hik.se>
- NNTP-Posting-Host: bstfirewall.bst.bls.com
- In-reply-to: Stefan Johansson's message of 15 Jan 1996 22:37:28 GMT
-
- In article <4dekv8$9ja@spider.hik.se> Stefan Johansson <mia95jos@mc.hik.se> writes:
-
- : Can someone help me with this little problem ?
-
- : If I use a system call to write to standard output, how do I makre this poossible with an integer
- : value ?
-
- : An example:
-
- : write(0, (the integer value), sizeof(int));
-
- There can be two interpretations to this problem:
- 1) You want the integer value directly written to standard output.
- 2) You want the ascii representation of the integer value to be written
- to standard output.
-
- 1) Try:
-
- write(0, &int_value, sizeof(int));
-
- 2) Try:
-
- char buf[10];
- sprintf(buf, "%d", int_value);
-
- write(0, buf, strlen(buf)-1);
-
- A couple of points, this is not portable, why not use the stdio library,
- this would then become
-
- 1)
- printf("%*s", sizeof(int), (char*)&int_value);
-
- 2)
- printf("%d", int_value);
- or equivalently
- fprintf(stdout, "%d", int_value);
-
-
- Secondly, on UNIX machines (which I am assuming you are using), file
- descriptor '0' is stdin and '1' is stdout, so the write should be:
-
- write(1, buf, strlen(buf));
-
- NB: The write is system dependent, so I am assuming:
- int write(int fildes, const void* buf, size_t nbytes);
-
- Regards
-
- -A.
- --
- | A.Champion |
-